package com.mmy.dao.sys;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.sys.TSysAddress;

public interface TSysAddressRepository extends JpaRepository<TSysAddress, Integer> {
	/**
	 * 获取最大值
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select MAX(iAddressID)  from tSysAddress ", nativeQuery = true)
	Object getMaxAddressID();

	/**
	 * 创建地址
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tSysAddress( iAddressID, iUserID, iType, iZoneID, cAddress, iPostcode, cName, cMobile, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, 0, 0, 0, NULL, 0, NULL, NULL, '2020-01-01 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int iAddressID);

	/* 查找该ID的招标信息 */

	@Query(value = "select * from tSysAddress where iAddressID=?1", nativeQuery = true)
	List<TSysAddress> findByiAddressID(int addressID);

	/* 删除收货信息 */
	@Transactional
	@Modifying
	@Query(value = "delete from tSysAddress where iAddressID in (:iAddressIDs)", nativeQuery = true)
	void deleteChecked(@Param("iAddressIDs") List<Integer> iAddressIDs);

	/**
	 * 通过地址ID查询地址
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select * from tSysAddress where iAddressID=?1", nativeQuery = true)
	TSysAddress findByAddressID(int iAddressID);

}
